from pylab import *

evec = loadtxt('JLA_WMAP9_vecs.txt')

frac1 = []
frac2 = []
frac3 = []
frac4 = []
frac5 = []
frac6 = []

for i in range(1,101):
    w = loadtxt('EoS/eos_'+str(i)+'.txt')
    dw= w[:,0]+1
    dw /= norm(dw)
    f0 = matmul(dw,evec[0,:])
    f1 = matmul(dw,evec[1,:])
    f2 = matmul(dw,evec[2,:])
    f3 = matmul(dw,evec[3,:])
    f4 = matmul(dw,evec[4,:])
    f5 = matmul(dw,evec[5,:])
    
    frac1.append( abs(f0) )
    frac2.append( (f1**2 + f0**2)**0.5 )
    frac3.append( (f2**2 + f1**2 + f0**2)**0.5 )
    frac4.append( (f3**2 + f2**2 + f1**2 + f0**2)**0.5 )
    frac5.append( (f4**2 + f3**2 + f2**2 + f1**2 + f0**2)**0.5 )
    frac6.append( (f5**2 + f4**2 + f3**2 + f2**2 + f1**2 + f0**2)**0.5 )

frac1 = array(frac1)
frac2 = array(frac2)
frac3 = array(frac3)
frac4 = array(frac4)
frac5 = array(frac5)
frac6 = array(frac6)

#hist(frac1, bins=15, label=r'1')
#hist(frac2, bins=15, label=r'2')
hist(frac3, bins=15, label=r'3')
hist(frac4, bins=15, label=r'4')
hist(frac5, bins=15, label=r'5')
hist(frac6, bins=15, label=r'6')

legend(loc='best',frameon=False)

frac_threshold = 0.8

print sum(frac1>frac_threshold)/100.
print sum(frac2>frac_threshold)/100.
print sum(frac3>frac_threshold)/100.
print sum(frac4>frac_threshold)/100.
print sum(frac5>frac_threshold)/100.
print sum(frac6>frac_threshold)/100.

show()
